package com.huaxin.hxmoduleworkorder.common.validator;

import com.huaxin.hxmoduleworkorder.common.annotation.validation.ValidInspectionOrderPublishType;
import com.huaxin.hxmoduleworkorder.common.enums.InspectionOrderPublishType;
import jakarta.validation.ConstraintValidator;
import jakarta.validation.ConstraintValidatorContext;

/**
 * 校验器：验证字符串是否为合法的 InspectionOrderPublishType 枚举值
 */
public class InspectionOrderPublishTypeValidator implements ConstraintValidator<ValidInspectionOrderPublishType, String> {
    @Override
    public boolean isValid(String value, ConstraintValidatorContext context) {
        // 允许 null 或空值通过（如果字段本身允许 null）
        // 非 null 时，必须是有效的枚举值
        return value == null || InspectionOrderPublishType.isValid(value);
    }
}
